//
//  NNDefender.h
//  CommonTool
//
//  Created by Name i on 2022/4/13.
//

#import <Foundation/Foundation.h>
#import "NSObject+Swizzling.h"


NS_ASSUME_NONNULL_BEGIN


#define     NNDefenderNotification @"    NNDefenderNotification"

#define     NNDefenderSeparatorWithFlag @"======================== Crash Log =========================="
#define     NNDefenderSeparator         @"================================================================"


#define     NNDefenderDefaultReturnNil  @"    NNDefender default is to return nil to avoid crash."
#define     NNDefenderDefaultIgnore     @"    NNDefender default is to ignore this operation to avoid crash."


#ifdef DEBUG
#define      NNDefenderLog(...) NSLog(@"%@",[NSString stringWithFormat:__VA_ARGS__])
#else
#define     NNDefenderLog(...)
#endif

#define key_errorName        @"errorName"
#define key_errorReason      @"errorReason"
#define key_errorPlace       @"errorPlace"
#define key_defaultToDo      @"defaultToDo"
#define key_callStackSymbols @"callStackSymbols"
#define key_exception        @"exception"



@protocol NNDefenderProtocol <NSObject>
@required
+ (void)exchangeMethod;
@end


typedef NS_OPTIONS(NSUInteger, TNDefenderType) {
    TNDefenderTypeNone         = 1 << 0,
    TNDefenderTypeKVC          = 1 << 1,
    TNDefenderTypeContainer    = 1 << 2,
    TNDefenderTypeString       = 1 << 3,
    TNDefenderTypeUnrecognized = 1 << 4,
    TNDefenderTypeTimer        = 1 << 5,
    TNDefenderTypeAll          = (TNDefenderTypeKVC |
                                  TNDefenderTypeContainer |
                                  TNDefenderTypeString |
                                  TNDefenderTypeUnrecognized |
                                  TNDefenderTypeTimer)
};


@interface NNDefender : NSObject

// 注册defender类型
+ (void)registerDefenderType:(TNDefenderType)defenderType;



/*
 * 崩溃的信息(控制台输出、通知)
 *
 *  @param exception   捕获到的异常
 *  @param defaultToDo 这个框架里默认的做法
 **/
+ (void)crashWithException:(NSException *)exception defaultToDo:(NSString *)defaultToDo;

@end

NS_ASSUME_NONNULL_END
